/*
 * Authors: Satnam Alag
 * http://www.manning.com/alag/
 * Copyright -- Collective Intelligence in Action
 * Updated: Filipe Ferraz Salgado  (filipesalgado@hotmail.com)
 *          Alexandre Albano       (aalbano@gmail.com)
 *          Instituto de Matemática e Estatística
 *          Universidade de São Paulo
 * 
 */

package br.org.groupware_workbench.commonalgorithms.analisadortextual_1_1.com.alag.ci.textanalysis.lucene.impl;

import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenStream;

public class CacheImpl {
    private Analyzer stemmer = null;
    
    public CacheImpl(String[] stopWords) {
        this.stemmer = new BrazilianStemStopWordAnalyzer(stopWords);
    }
    
    protected String getStemmedText(String text) throws IOException {
        StringBuilder sb = new StringBuilder();
        Reader reader = new StringReader(text);
        TokenStream tokenStream = this.stemmer.tokenStream(null, reader);
        Token token = tokenStream.next();
        while (token != null) {
            sb.append(token.termText());
            token = tokenStream.next();
            if (token != null) {
                sb.append(" ");
            }
        }
        return sb.toString();    
    }
}
